tests = int(input())
for _ in range(tests):
students = int(input())
ronde = [int(x) for x in input().split()]
res = dict()
for i, x in enumerate(ronde[:-1]):
res[x - ronde[i + 1]] = res.get(x - ronde[i + 1], 0) + 1
possible = True
compte = -1
for k, v in res.items():
if k not in {-1, 1}:
compte += 1
if v > 1:
possible = False
if -1 in res and 1 in res:
possible = False
if compte > 0:
possible = False
if possible:
print("YES")
else:
print("NO")
#include <bits/stdc++.h>
#define in(x) return void(cout << x)
using namespace std;
int a[1007];
void solve()
{
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
/// !counter;
int dem = 0;
for (int i = 1; i < n; i++)
dem += (a[i] > a[i + 1]);
if ( (dem == 0) || (dem == 1 && a[n] < a[1]) ) in("YES\n");
/// counter;
dem = 0;
for (int i = 1; i < n; i++)
dem += (a[i] < a[i + 1]);
if ( (dem == 0) || (dem == 1 && a[n] > a[1]) ) in("YES\n");
cout << "NO\n";
}
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define task "A"
if (fopen(task".inp","r"))
{
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
574A - Bear and Elections | 352B - Jeff and Periods |
1244A - Pens and Pencils | 1670A - Prof Slim |
1189A - Keanu Reeves | 678A - Johny Likes Numbers |
1699C - The Third Problem | 1697D - Guess The String |
754B - Ilya and tic-tac-toe game | 760A - Petr and a calendar |
1573A - Countdown | 166A - Rank List |
1631B - Fun with Even Subarrays | 727A - Transformation from A to B |
822B - Crossword solving | 1623A - Robot Cleaner |
884B - Japanese Crosswords Strike Back | 862B - Mahmoud and Ehab and the bipartiteness |
429A - Xor-tree | 1675C - Detective Task |
950A - Left-handers Right-handers and Ambidexters | 672B - Different is Good |
1C - Ancient Berland Circus | 721A - One-dimensional Japanese Crossword |
1715B - Beautiful Array | 60B - Serial Time |
453A - Little Pony and Expected Maximum | 1715A - Crossmarket |
1715C - Monoblock | 1512C - A-B Palindrome |